package com.yuwei.notice.adapter

import android.graphics.Color
import android.widget.ImageView
import android.widget.TextView
import androidx.cardview.widget.CardView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.yuwei.http.entity.NoticeEntityItem
import com.yuwei.notice.R

class NoticeAdapter : BaseQuickAdapter<NoticeEntityItem, BaseViewHolder>(
    R.layout.notice_item
) {

    override fun convert(holder: BaseViewHolder, item: NoticeEntityItem) {
        val cardView = holder.getView<CardView>(R.id.notice_cv)
        cardView.radius = 15f
        val imageView = holder.getView<ImageView>(R.id.notice_item_iv)
        when(item.type){
            "社区活动"->{
                imageView.setBackgroundResource(R.drawable.notice_item_image_bg1)
                imageView.setImageResource(R.drawable.notice_calendar)
            }
            "安全提醒"->{
                imageView.setBackgroundResource(R.drawable.notice_item_image_bg2)
                imageView.setImageResource(R.drawable.notice_shield)
            }
            "环境维护"->{
                imageView.setBackgroundResource(R.drawable.notice_item_image_bg3)
                imageView.setImageResource(R.drawable.notice_tree)
            }
        }
        holder.setText(R.id.notice_item_tv_title,item.type)
        holder.setText(R.id.notice_item_tv_content,item.content)
        holder.setText(R.id.notice_item_tv_time,item.publishTime)
        val textView = holder.getView<TextView>(R.id.notice_item_tv_status)
        when(item.status){
            "立刻报名"->{
                textView.setBackgroundResource(R.drawable.notice_item_tv_bg1)
                textView.text = item.status
                textView.setTextColor(Color.WHITE)
            }
            "已读"->{
                textView.setBackgroundResource(R.drawable.notice_item_tv_bg2)
                textView.text = item.status
                textView.setTextColor(Color.BLUE)
            }

        }
    }
}